package com.lee.limiter.maplimit;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * token桶的池
 *  内部类实现的单例
 * User:liwei
 * Date:2017/9/1
 * Time:15:10
 */
public class TokenBucketPool {

    private static class Inner{
        static TokenBucketPool singleton = new TokenBucketPool();
    }

    private TokenBucketPool(){
        pool = new ConcurrentHashMap<>();
    }

    private Map<String,TokenBucket> pool;

    public static TokenBucketPool getInstace(){
        return Inner.singleton;
    }

    public TokenBucket getBucketByKey(String key){
        return pool.get(key);
    }

    public TokenBucket putBucket(String key, TokenBucket tokenBucket){
        return pool.put(key, tokenBucket);
    }

    public void clear(String key){
        pool.remove(key);
    }

    public void clear(){
        pool.clear();
    }

    public void show(){
        System.out.println(pool);
    }
}
